﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace GC的工作
{
    public class A
    {
        private B objB;
        public A(B o)
        {
            objB = o;
        }
        ~A()
        {
            Console.WriteLine("Destory A.");
        }
    }
    public class B
    {
        private C objC;
        public B(C o)
        {
            objC = o;
        }
        ~B()
        {
            Console.WriteLine("Destory B.");
        }
    }
    public class C
    {
        ~C()
        {
            Console.WriteLine("Destory C.");
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            A a = new A(new B(new C()));
            //强制执行垃圾回收 
            GC.Collect(0);
            Console.WriteLine(Thread.CurrentThread.GetHashCode());
            GC.WaitForPendingFinalizers();
            Console.WriteLine("是否最然才执行");
            Console.WriteLine(Thread.CurrentThread.GetHashCode());
        }
    }
}
